package com.kyleswebspace.propertyanalyzer.gui;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;

import com.kyleswebspace.parser.FieldParser;
import com.kyleswebspace.propertyanalyzer.config.ArcaFont;
import com.kyleswebspace.propertyanalyzer.config.BorderBox;
import com.kyleswebspace.propertyanalyzer.config.ColorBox;
import com.kyleswebspace.propertyanalyzer.model.DataModel;

import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.FocusEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class ExpensesPanel extends JPanel implements Updateable, KeyListener,
		MouseListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 9078808230290423461L;

	private DataModel dm;
	private FocusMediator fm;

	private JLabel annualLabel, percentageLabel;
	private JLabel propTaxesLabel;
	private JTextField propTaxesField;
	private JTextField propTaxesPercentageField;
	private JLabel insuranceLabel;
	private JTextField insuranceField;
	private JTextField insurancePercentageField;
	private JLabel waterSewerLabel;
	private JTextField waterSewerField;
	private JTextField waterSewerPercentageField;
	private JLabel heatLabel;
	private JTextField heatField;
	private JTextField heatPercentageField;
	private JLabel hydroLabel;
	private JTextField hydroField;
	private JTextField hydroPercentageField;
	private JLabel maintenanceLabel;
	private JTextField maintenanceField;
	private JTextField maintenanceFieldB;
	private JTextField maintenancePercentageField;
	private JLabel managementLabel;
	private JTextField managementField;
	private JTextField managementFieldB;
	private JTextField managementPercentageField;
	private JLabel snowRemovalLabel;
	private JTextField snowRemovalField;
	private JTextField snowRemovalPercentageField;
	private JLabel superIntendantLabel;
	private JTextField superIntendantField;
	private JTextField superIntendantPercentageField;
	private JLabel advertisingLabel;
	private JTextField advertisingField;
	private JTextField advertisingPercentageField;
	private JLabel suppliesLabel;
	private JTextField suppliesField;
	private JTextField suppliesPercentageField;
	private JLabel garbageLabel;
	private JTextField garbageField;
	private JTextField garbagePercentageField;
	private JLabel lawnLabel;
	private JTextField lawnField;
	private JTextField lawnPercentageField;
	private JLabel licensesLabel;
	private JTextField licensesField;
	private JTextField licensesPercentageField;
	private JLabel accountingLabel;
	private JTextField accountingField;
	private JTextField accountingPercentageField;
	private JLabel legalLabel;
	private JTextField legalField;
	private JTextField legalPercentageField;
	private JLabel cleaningLabel;
	private JTextField cleaningField;
	private JTextField cleaningPercentageField;
	private JLabel poolLabel;
	private JTextField poolField;
	private JTextField poolPercentageField;
	private JLabel elevatorLabel;
	private JTextField elevatorField;
	private JTextField elevatorPercentageField;
	private JLabel pestControlLabel;
	private JTextField pestControlField;
	private JTextField pestControlPercentageField;
	private JLabel replacementsLabel;
	private JTextField replacementsField;
	private JTextField replacementsPercentageField;
	private JLabel condoFeesLabel;
	private JTextField condoFeesField;
	private JTextField condoFeesPercentageField;
	private JTextField optional1Label;
	private JTextField optional1Field;
	private JTextField optional1FieldPercentage;
	private JTextField optional2Label;
	private JTextField optional2Field;
	private JTextField optional2FieldPercentage;
	private JLabel otherLabel;
	private JTextField otherField;
	private JTextField otherPercentageField;
	private JLabel totalExpensesLabel;
	private JTextField totalExpensesField;
	private JTextField totalExpensesPercentageField;

	private final Color editableColor = ColorBox.fieldColor;
	private Color overridableColor = ColorBox.overridableColor;
	private Color overriddenColor = ColorBox.overriddenColor;
	private Color innerPanelColor = ColorBox.innerPanelColor;
	private Font appFont = ArcaFont.appFont;

	public ExpensesPanel(DataModel dm, FocusMediator fm) {
		this.dm = dm;
		this.fm = fm;
		dm.register(this);

		this.setLayout(new GridBagLayout());
		TitledBorder title;
		title = BorderFactory.createTitledBorder("Expenses");
		this.setBorder(title);
		this.setBackground(innerPanelColor);

		GridBagConstraints constraints = new GridBagConstraints();
		constraints.ipadx = 20; // PADDING

		// annual label
		annualLabel = new JLabel("Annual ");
		annualLabel.setFont(appFont);
		annualLabel.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridx = 3;
		constraints.gridy = 0;
		constraints.gridwidth = 1;
		constraints.anchor = GridBagConstraints.EAST;
		this.add(annualLabel, constraints);

		// percentage label
		percentageLabel = new JLabel("%     ");
		percentageLabel.setFont(appFont);
		percentageLabel.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridx = 4;
		this.add(percentageLabel, constraints);

		// property taxes
		propTaxesLabel = new JLabel("Property Taxes");
		propTaxesLabel.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 1;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(propTaxesLabel, constraints);

		propTaxesField = new JTextField(4);
		fm.setPropertyTaxesField(propTaxesField);
		propTaxesField.addFocusListener(this);
		propTaxesField.addKeyListener(this);
		propTaxesField.setFont(appFont);
		propTaxesField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		propTaxesField.setBackground(editableColor);
		this.add(propTaxesField, constraints);

		propTaxesPercentageField = new JTextField(3);
		propTaxesPercentageField.addFocusListener(this);
		propTaxesPercentageField.setFont(appFont);
		propTaxesPercentageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(propTaxesPercentageField, constraints);

		// insurance
		insuranceLabel = new JLabel("Insurance");
		insuranceLabel.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 2;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(insuranceLabel, constraints);
		insuranceField = new JTextField(4);
		fm.setInsuranceField(insuranceField);
		insuranceField.addFocusListener(this);
		insuranceField.addKeyListener(this);
		insuranceField.setFont(appFont);
		insuranceField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		insuranceField.setBackground(editableColor);
		this.add(insuranceField, constraints);

		insurancePercentageField = new JTextField(3);
		insurancePercentageField.addFocusListener(this);
		insurancePercentageField.setFont(appFont);
		insurancePercentageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(insurancePercentageField, constraints);

		// water/sewer
		waterSewerLabel = new JLabel("Water / Sewer");
		waterSewerLabel.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 3;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(waterSewerLabel, constraints);
		waterSewerField = new JTextField(4);
		fm.setWaterSewerField(waterSewerField);
		waterSewerField.addFocusListener(this);
		waterSewerField.addKeyListener(this);
		waterSewerField.setFont(appFont);
		waterSewerField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		waterSewerField.setBackground(editableColor);
		this.add(waterSewerField, constraints);

		waterSewerPercentageField = new JTextField(3);
		waterSewerPercentageField.addFocusListener(this);
		waterSewerPercentageField.setFont(appFont);
		waterSewerPercentageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(waterSewerPercentageField, constraints);

		// heat(gas)
		heatLabel = new JLabel("Heat (Gas)");
		heatLabel.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 4;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(heatLabel, constraints);
		heatField = new JTextField(4);
		fm.setHeatField(heatField);
		heatField.addFocusListener(this);
		heatField.addKeyListener(this);
		heatField.setFont(appFont);
		heatField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		heatField.setBackground(editableColor);
		this.add(heatField, constraints);

		heatPercentageField = new JTextField(3);
		heatPercentageField.addFocusListener(this);
		heatPercentageField.setFont(appFont);
		heatPercentageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(heatPercentageField, constraints);

		// hydro(electricity)
		hydroLabel = new JLabel("Hydro (Electricity)");
		hydroLabel.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 5;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(hydroLabel, constraints);
		hydroField = new JTextField(4);
		fm.setHydroField(hydroField);
		hydroField.addFocusListener(this);
		hydroField.addKeyListener(this);
		hydroField.setFont(appFont);
		hydroField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		hydroField.setBackground(editableColor);
		this.add(hydroField, constraints);

		hydroPercentageField = new JTextField(3);
		hydroPercentageField.addFocusListener(this);
		hydroPercentageField.setFont(appFont);
		hydroPercentageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(hydroPercentageField, constraints);

		// maintenance
		maintenanceLabel = new JLabel("Maintenance");
		maintenanceLabel.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 6;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(maintenanceLabel, constraints);
		maintenanceField = new JTextField(2);
		fm.setMaintenanceField(maintenanceField);
		maintenanceField.addFocusListener(this);
		maintenanceField.addKeyListener(this);
		maintenanceField.setFont(appFont);
		maintenanceFieldB = new JTextField(4);
		fm.setMaintenanceFieldB(maintenanceFieldB);
		maintenanceFieldB.addFocusListener(this);
		maintenanceFieldB.addMouseListener(this);
		maintenanceFieldB.addKeyListener(this);
		maintenanceFieldB.setFont(appFont);
		maintenanceFieldB.setBackground(overridableColor);
		maintenanceField.setHorizontalAlignment(JTextField.RIGHT);
		maintenanceFieldB.setHorizontalAlignment(JTextField.RIGHT);
		maintenanceFieldB.setBorder(BorderBox.fieldBorder);
		maintenanceFieldB
				.setToolTipText("<html>CMHC mortgage insurance uses<br/>"
						+ "the rate of $400 to<br/>"
						+ "$800/door/year depending on<br/>"
						+ "age of property when they<br/>"
						+ "assess the value of a property.</html>");
		constraints.gridwidth = 1;
		constraints.gridx = 2;
		constraints.anchor = GridBagConstraints.EAST;
		maintenanceField.setBackground(editableColor);
		this.add(maintenanceField, constraints);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		this.add(maintenanceFieldB, constraints);

		maintenancePercentageField = new JTextField(3);
		maintenancePercentageField.addFocusListener(this);
		maintenancePercentageField.setFont(appFont);
		maintenancePercentageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(maintenancePercentageField, constraints);

		// management
		managementLabel = new JLabel("Management                    ");
		managementLabel.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 7;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(managementLabel, constraints);
		managementField = new JTextField(2);
		fm.setManagementField(managementField);
		managementField.setFont(appFont);
		managementField.addFocusListener(this);
		managementField.addKeyListener(this);
		managementFieldB = new JTextField(4);
		fm.setManagementFieldB(managementFieldB);
		managementFieldB.addFocusListener(this);
		managementFieldB.addMouseListener(this);
		managementFieldB.addKeyListener(this);
		managementFieldB.setFont(appFont);
		managementFieldB.setBackground(overridableColor);
		managementField.setHorizontalAlignment(JTextField.RIGHT);
		managementFieldB.setHorizontalAlignment(JTextField.RIGHT);
		managementFieldB.setBorder(BorderBox.fieldBorder);
		managementFieldB
				.setToolTipText("<html>Typically 5 to 8% of rents collected but may vary and/or<br/>"
						+ "not include hidden costs such as fill rates. Some<br/>"
						+ "management companies may charge a flat rate per door,<br/>"
						+ "some will charge based on rents collected and some may<br/>"
						+ "charge based upon rents charged. This rate will aslo vary<br/>"
						+ "depending upon location and size of property. If the<br/>"
						+ "property is larger (6 units plus) and in a larger municipality<br/>"
						+ "then the rate could be as low as 4% but if it is a single </html>");
		constraints.gridwidth = 1;
		constraints.gridx = 2;
		constraints.anchor = GridBagConstraints.EAST;
		managementField.setBackground(editableColor);
		this.add(managementField, constraints);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		this.add(managementFieldB, constraints);

		managementPercentageField = new JTextField(3);
		managementPercentageField.addFocusListener(this);
		managementPercentageField.setFont(appFont);
		managementPercentageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(managementPercentageField, constraints);

		// snow removal
		snowRemovalLabel = new JLabel("Snow Removal");
		snowRemovalLabel.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 8;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(snowRemovalLabel, constraints);
		snowRemovalField = new JTextField(4);
		fm.setSnowRemovalField(snowRemovalField);
		snowRemovalField.addFocusListener(this);
		snowRemovalField.addKeyListener(this);
		snowRemovalField.setFont(appFont);
		snowRemovalField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		snowRemovalField.setBackground(editableColor);
		this.add(snowRemovalField, constraints);

		snowRemovalPercentageField = new JTextField(3);
		snowRemovalPercentageField.addFocusListener(this);
		snowRemovalPercentageField.setFont(appFont);
		snowRemovalPercentageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(snowRemovalPercentageField, constraints);

		// super intendant
		superIntendantLabel = new JLabel("Super Intendant");
		superIntendantLabel.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 9;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(superIntendantLabel, constraints);
		superIntendantField = new JTextField(4);
		fm.setSuperIntendantField(superIntendantField);
		superIntendantField.addFocusListener(this);
		superIntendantField.addKeyListener(this);
		superIntendantField.setFont(appFont);
		superIntendantField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		superIntendantField.setBackground(editableColor);
		this.add(superIntendantField, constraints);

		superIntendantPercentageField = new JTextField(3);
		superIntendantPercentageField.addFocusListener(this);
		superIntendantPercentageField.setFont(appFont);
		superIntendantPercentageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(superIntendantPercentageField, constraints);

		// advertising
		advertisingLabel = new JLabel("Advertising");
		advertisingLabel.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 10;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(advertisingLabel, constraints);
		advertisingField = new JTextField(4);
		fm.setAdvertisingField(advertisingField);
		advertisingField.addFocusListener(this);
		advertisingField.addKeyListener(this);
		advertisingField.setFont(appFont);
		advertisingField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		advertisingField.setBackground(editableColor);
		this.add(advertisingField, constraints);

		advertisingPercentageField = new JTextField(3);
		advertisingPercentageField.addFocusListener(this);
		advertisingPercentageField.setFont(appFont);
		advertisingPercentageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(advertisingPercentageField, constraints);

		// supplies
		suppliesLabel = new JLabel("Supplies");
		suppliesLabel.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 11;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(suppliesLabel, constraints);
		suppliesField = new JTextField(4);
		fm.setSuppliesField(suppliesField);
		suppliesField.addFocusListener(this);
		suppliesField.addKeyListener(this);
		suppliesField.setFont(appFont);
		suppliesField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		suppliesField.setBackground(editableColor);
		this.add(suppliesField, constraints);

		suppliesPercentageField = new JTextField(3);
		suppliesPercentageField.addFocusListener(this);
		suppliesPercentageField.setFont(appFont);
		suppliesPercentageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(suppliesPercentageField, constraints);

		// garbage
		garbageLabel = new JLabel("Garbage");
		garbageLabel.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 12;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(garbageLabel, constraints);
		garbageField = new JTextField(4);
		fm.setGarbageField(garbageField);
		garbageField.addFocusListener(this);
		garbageField.addKeyListener(this);
		garbageField.setFont(appFont);
		garbageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		garbageField.setBackground(editableColor);
		this.add(garbageField, constraints);

		garbagePercentageField = new JTextField(3);
		garbagePercentageField.addFocusListener(this);
		garbagePercentageField.setFont(appFont);
		garbagePercentageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(garbagePercentageField, constraints);

		// lawn
		lawnLabel = new JLabel("Lawn");
		lawnLabel.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 13;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(lawnLabel, constraints);
		lawnField = new JTextField(4);
		fm.setLawnField(lawnField);
		lawnField.addFocusListener(this);
		lawnField.addKeyListener(this);
		lawnField.setFont(appFont);
		lawnField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		lawnField.setBackground(editableColor);
		this.add(lawnField, constraints);

		lawnPercentageField = new JTextField(3);
		lawnPercentageField.addFocusListener(this);
		lawnPercentageField.setFont(appFont);
		lawnPercentageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(lawnPercentageField, constraints);

		// licenses
		licensesLabel = new JLabel("Licenses");
		licensesLabel.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 14;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(licensesLabel, constraints);
		licensesField = new JTextField(4);
		fm.setLicensesField(licensesField);
		licensesField.addFocusListener(this);
		licensesField.addKeyListener(this);
		licensesField.setFont(appFont);
		licensesField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		licensesField.setBackground(editableColor);
		this.add(licensesField, constraints);

		licensesPercentageField = new JTextField(3);
		licensesPercentageField.addFocusListener(this);
		licensesPercentageField.setFont(appFont);
		licensesPercentageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(licensesPercentageField, constraints);

		// accounting
		accountingLabel = new JLabel("Accounting");
		accountingLabel.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 15;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(accountingLabel, constraints);
		accountingField = new JTextField(4);
		fm.setAccountingField(accountingField);
		accountingField.addFocusListener(this);
		accountingField.addKeyListener(this);
		accountingField.setFont(appFont);
		accountingField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		accountingField.setBackground(editableColor);
		this.add(accountingField, constraints);

		accountingPercentageField = new JTextField(3);
		accountingPercentageField.addFocusListener(this);
		accountingPercentageField.setFont(appFont);
		accountingPercentageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(accountingPercentageField, constraints);

		// legal
		legalLabel = new JLabel("Legal");
		legalLabel.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 16;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(legalLabel, constraints);
		legalField = new JTextField(4);
		fm.setLegalField(legalField);
		legalField.addFocusListener(this);
		legalField.addKeyListener(this);
		legalField.setFont(appFont);
		legalField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		legalField.setBackground(editableColor);
		this.add(legalField, constraints);

		legalPercentageField = new JTextField(3);
		legalPercentageField.addFocusListener(this);
		legalPercentageField.setFont(appFont);
		legalPercentageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(legalPercentageField, constraints);

		// cleaning
		cleaningLabel = new JLabel("Cleaning");
		cleaningLabel.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 17;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(cleaningLabel, constraints);
		cleaningField = new JTextField(4);
		fm.setCleaningField(cleaningField);
		cleaningField.addFocusListener(this);
		cleaningField.addKeyListener(this);
		cleaningField.setFont(appFont);
		cleaningField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		cleaningField.setBackground(editableColor);
		this.add(cleaningField, constraints);

		cleaningPercentageField = new JTextField(3);
		cleaningPercentageField.addFocusListener(this);
		cleaningPercentageField.setFont(appFont);
		cleaningPercentageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(cleaningPercentageField, constraints);

		// pool
		poolLabel = new JLabel("Pool");
		poolLabel.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 18;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(poolLabel, constraints);
		poolField = new JTextField(4);
		fm.setPoolField(poolField);
		poolField.addFocusListener(this);
		poolField.addKeyListener(this);
		poolField.setFont(appFont);
		poolField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		poolField.setBackground(editableColor);
		this.add(poolField, constraints);

		poolPercentageField = new JTextField(3);
		poolPercentageField.addFocusListener(this);
		poolPercentageField.setFont(appFont);
		poolPercentageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(poolPercentageField, constraints);

		// elevator
		elevatorLabel = new JLabel("Elevator");
		elevatorLabel.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 19;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(elevatorLabel, constraints);
		elevatorField = new JTextField(4);
		fm.setElevatorField(elevatorField);
		elevatorField.addFocusListener(this);
		elevatorField.addKeyListener(this);
		elevatorField.setFont(appFont);
		elevatorField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		elevatorField.setBackground(editableColor);
		this.add(elevatorField, constraints);

		elevatorPercentageField = new JTextField(3);
		elevatorPercentageField.addFocusListener(this);
		elevatorPercentageField.setFont(appFont);
		elevatorPercentageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(elevatorPercentageField, constraints);

		// pest control
		pestControlLabel = new JLabel("Pest Control");
		pestControlLabel.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 20;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(pestControlLabel, constraints);
		pestControlField = new JTextField(4);
		fm.setPestControlField(pestControlField);
		pestControlField.addFocusListener(this);
		pestControlField.addKeyListener(this);
		pestControlField.setFont(appFont);
		pestControlField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		pestControlField.setBackground(editableColor);
		this.add(pestControlField, constraints);

		pestControlPercentageField = new JTextField(3);
		pestControlPercentageField.addFocusListener(this);
		pestControlPercentageField.setFont(appFont);
		pestControlPercentageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(pestControlPercentageField, constraints);

		// replacements
		replacementsLabel = new JLabel("Replacements");
		replacementsLabel.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 21;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(replacementsLabel, constraints);
		replacementsField = new JTextField(4);
		fm.setReplacementsField(replacementsField);
		replacementsField.addFocusListener(this);
		replacementsField.addKeyListener(this);
		replacementsField.setFont(appFont);
		replacementsField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		replacementsField.setBackground(editableColor);
		this.add(replacementsField, constraints);

		replacementsPercentageField = new JTextField(3);
		replacementsPercentageField.addFocusListener(this);
		replacementsPercentageField.setFont(appFont);
		replacementsPercentageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(replacementsPercentageField, constraints);

		// condo fees
		condoFeesLabel = new JLabel("Condo Fees");
		condoFeesLabel.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 22;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(condoFeesLabel, constraints);
		condoFeesField = new JTextField(4);
		fm.setCondoFeesField(condoFeesField);
		condoFeesField.addFocusListener(this);
		condoFeesField.addKeyListener(this);
		condoFeesField.setFont(appFont);
		condoFeesField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		condoFeesField.setBackground(editableColor);
		this.add(condoFeesField, constraints);

		condoFeesPercentageField = new JTextField(3);
		condoFeesPercentageField.addFocusListener(this);
		condoFeesPercentageField.setFont(appFont);
		condoFeesPercentageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(condoFeesPercentageField, constraints);

		// optional #1
		optional1Label = new JTextField(10);
		optional1Label.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 23;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(optional1Label, constraints);
		optional1Field = new JTextField(4);
		fm.setOptionalExpensesFieldA(optional1Field);
		optional1Field.addFocusListener(this);
		optional1Field.addKeyListener(this);
		optional1Field.setFont(appFont);
		optional1Field.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		optional1Field.setBackground(editableColor);
		this.add(optional1Field, constraints);

		optional1FieldPercentage = new JTextField(3);
		optional1FieldPercentage.addFocusListener(this);
		optional1FieldPercentage.setFont(appFont);
		optional1FieldPercentage.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(optional1FieldPercentage, constraints);

		// optional #2
		optional2Label = new JTextField(10);
		optional2Label.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 24;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(optional2Label, constraints);
		optional2Field = new JTextField(4);
		fm.setOptionalExpensesFieldB(optional2Field);
		optional2Field.addFocusListener(this);
		optional2Field.addKeyListener(this);
		optional2Field.setFont(appFont);
		optional2Field.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		optional2Field.setBackground(editableColor);
		this.add(optional2Field, constraints);

		optional2FieldPercentage = new JTextField(3);
		optional2FieldPercentage.addFocusListener(this);
		optional2FieldPercentage.setFont(appFont);
		optional2FieldPercentage.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(optional2FieldPercentage, constraints);

		// other
		otherLabel = new JLabel("Other");
		otherLabel.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 25;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(otherLabel, constraints);
		otherField = new JTextField(4);
		fm.setOtherExpensesField(otherField);
		otherField.addFocusListener(this);
		otherField.addKeyListener(this);
		otherField.setFont(appFont);
		otherField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		otherField.setBackground(editableColor);
		this.add(otherField, constraints);

		otherPercentageField = new JTextField(3);
		otherPercentageField.addFocusListener(this);
		otherPercentageField.setFont(appFont);
		otherPercentageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(otherPercentageField, constraints);

		// separator
		constraints.gridx = 0;
		constraints.gridwidth = 5;
		constraints.gridy = 26;
		constraints.fill = GridBagConstraints.HORIZONTAL;
		this.add(new JSeparator(SwingConstants.HORIZONTAL), constraints);
		constraints.fill = GridBagConstraints.NONE;

		// total expenses
		totalExpensesLabel = new JLabel("Total Expenses");
		totalExpensesLabel.setFont(appFont);
		constraints.gridx = 0;
		constraints.gridy = 27;
		constraints.gridwidth = 3;
		constraints.anchor = GridBagConstraints.WEST;
		this.add(totalExpensesLabel, constraints);
		totalExpensesField = new JTextField(4);
		totalExpensesField.addFocusListener(this);
		totalExpensesField.setFocusable(false);
		totalExpensesField.setFont(appFont);
		totalExpensesField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.gridwidth = 1;
		constraints.gridx = 3;
		constraints.anchor = GridBagConstraints.EAST;
		this.add(totalExpensesField, constraints);

		totalExpensesPercentageField = new JTextField(3);
		totalExpensesPercentageField.addFocusListener(this);
		totalExpensesPercentageField.setBorder(BorderBox.fieldBorder);
		totalExpensesPercentageField
				.setToolTipText("<html>Percentage values are<br/>"
						+ "calculated as the division of<br/>"
						+ "a given expense against<br/>"
						+ "the base GOI (not the<br/>"
						+ "effective GOI).</html>");
		totalExpensesPercentageField.setFont(appFont);
		totalExpensesPercentageField.setHorizontalAlignment(JTextField.RIGHT);
		constraints.anchor = GridBagConstraints.EAST;
		constraints.gridx = 4;
		this.add(totalExpensesPercentageField, constraints);

		//update overridden values, if any
		if(dm.isOverrideMaintenance()) {
			maintenanceFieldB.setBackground(overriddenColor);
		}
		if(dm.isOverrideManagement()) {
			managementFieldB.setBackground(overriddenColor);
		}
		
		updateFields();
	}

	public void updateFields() {
		this.propTaxesField.setText(dm.getPropertyTaxes());
		this.propTaxesPercentageField.setText(dm.getPropertyTaxesPercentage()
				+ "%");
		this.insuranceField.setText(dm.getInsurance());
		this.insurancePercentageField
				.setText(dm.getInsurancePercentage() + "%");
		this.waterSewerField.setText(dm.getWaterSewer());
		this.waterSewerPercentageField.setText(dm.getWaterSewerPercentage()
				+ "%");
		this.heatField.setText(dm.getHeat());
		this.heatPercentageField.setText(dm.getHeatPercentage() + "%");
		this.hydroField.setText(dm.getHydro());
		this.hydroPercentageField.setText(dm.getHydroPercentage() + "%");
		this.maintenanceField.setText(dm.getMaintenanceA() + "/dr");
		this.maintenanceFieldB.setText(dm.getMaintenanceB());
		this.maintenancePercentageField.setText(dm.getMaintenancePercentage()
				+ "%");
		this.managementField.setText(dm.getManagementA() + "%");
		this.managementFieldB.setText(dm.getManagementB());
		this.managementPercentageField.setText(dm.getManagementPercentage()
				+ "%");
		this.snowRemovalField.setText(dm.getSnowRemoval());
		this.snowRemovalPercentageField.setText(dm.getSnowRemovalPercentage()
				+ "%");
		this.superIntendantField.setText(dm.getSuperIntendant());
		this.superIntendantPercentageField.setText(dm
				.getSuperIntendantPercentage()
				+ "%");
		this.advertisingField.setText(dm.getAdvertising());
		this.advertisingPercentageField.setText(dm.getAdvertisingPercentage()
				+ "%");
		this.suppliesField.setText(dm.getSupplies());
		this.suppliesPercentageField.setText(dm.getSuppliesPercentage() + "%");
		this.garbageField.setText(dm.getGarbage());
		this.garbagePercentageField.setText(dm.getGarbagePercentage() + "%");
		this.lawnField.setText(dm.getLawn());
		this.lawnPercentageField.setText(dm.getLawnPercentage() + "%");
		this.licensesField.setText(dm.getLicenses());
		this.licensesPercentageField.setText(dm.getLicensesPercentage() + "%");
		this.accountingField.setText(dm.getAccounting());
		this.accountingPercentageField.setText(dm.getAccountingPercentage()
				+ "%");
		this.legalField.setText(dm.getLegal());
		this.legalPercentageField.setText(dm.getLegalPercentage() + "%");
		this.cleaningField.setText(dm.getCleaning());
		this.cleaningPercentageField.setText(dm.getCleaningPercentage() + "%");
		this.poolField.setText(dm.getPool());
		this.poolPercentageField.setText(dm.getPoolPercentage() + "%");
		this.elevatorField.setText(dm.getElevator());
		this.elevatorPercentageField.setText(dm.getElevatorPercentage() + "%");
		this.pestControlField.setText(dm.getPestControl());
		this.pestControlPercentageField.setText(dm.getPestControlPercentage()
				+ "%");
		this.replacementsField.setText(dm.getReplacements());
		this.replacementsPercentageField.setText(dm.getReplacementsPercentage()
				+ "%");
		this.condoFeesField.setText(dm.getCondoFees());
		this.condoFeesPercentageField
				.setText(dm.getCondoFeesPercentage() + "%");
		this.optional1Label.setText(dm.getOptional1Label());
		this.optional1Field.setText(dm.getOptional1Field());
		this.optional1FieldPercentage
				.setText(dm.getOptional1Percentage() + "%");
		this.optional2Label.setText(dm.getOptional2Label());
		this.optional2Field.setText(dm.getOptional2Field());
		this.optional2FieldPercentage
				.setText(dm.getOptional2Percentage() + "%");
		this.otherField.setText(dm.getOtherExpenses());
		this.otherPercentageField
				.setText(dm.getOtherExpensesPercentage() + "%");
		this.totalExpensesField.setText(dm.getTotalExpenses());
		this.totalExpensesPercentageField.setText(dm
				.getTotalExpensesPercentage()
				+ "%");

		if (dm.isOverrideMaintenance())
			maintenanceFieldB.setBackground(ColorBox.overriddenColor);
		if (dm.isOverrideManagement())
			managementFieldB.setBackground(ColorBox.overriddenColor);
	}
	
	public void updateModel() {
		dm.setPropertyTaxes(FieldParser.parseInteger(this.propTaxesField
				.getText().replaceAll(",", "")));
		dm.setInsurance(FieldParser.parseInteger(this.insuranceField.getText()
				.replaceAll(",", "")));
		dm.setWaterSewer(FieldParser.parseInteger(this.waterSewerField
				.getText().replaceAll(",", "")));
		dm.setHeat(FieldParser.parseInteger(this.heatField.getText()
				.replaceAll(",", "")));
		dm.setHydro(FieldParser.parseInteger(this.hydroField.getText()
				.replaceAll(",", "")));
		dm.setMaintenanceA(FieldParser.parseInteger(this.maintenanceField
				.getText().replaceAll(",", "")));
		dm.setManagementA(FieldParser.parseDecimal(this.managementField
				.getText().replaceAll(",", "")));
		dm.setSnowRemoval(FieldParser.parseInteger(this.snowRemovalField
				.getText().replaceAll(",", "")));
		dm.setSuperIntendant(FieldParser.parseInteger(this.superIntendantField
				.getText().replaceAll(",", "")));
		dm.setAdvertising(FieldParser.parseInteger(this.advertisingField
				.getText().replaceAll(",", "")));
		dm.setSupplies(FieldParser.parseInteger(this.suppliesField.getText()
				.replaceAll(",", "")));
		dm.setGarbage(FieldParser.parseInteger(this.garbageField.getText()
				.replaceAll(",", "")));
		dm.setLawn(FieldParser.parseInteger(this.lawnField.getText()
				.replaceAll(",", "")));
		dm.setLicenses(FieldParser.parseInteger(this.licensesField.getText()
				.replaceAll(",", "")));
		dm.setAccounting(FieldParser.parseInteger(this.accountingField
				.getText().replaceAll(",", "")));
		dm.setLegal(FieldParser.parseInteger(this.legalField.getText()
				.replaceAll(",", "")));
		dm.setCleaning(FieldParser.parseInteger(this.cleaningField.getText()
				.replaceAll(",", "")));
		dm.setPool(FieldParser.parseInteger(this.poolField.getText()
				.replaceAll(",", "")));
		dm.setElevator(FieldParser.parseInteger(this.elevatorField.getText()
				.replaceAll(",", "")));
		dm.setPestControl(FieldParser.parseInteger(this.pestControlField
				.getText().replaceAll(",", "")));
		dm.setReplacements(FieldParser.parseInteger(this.replacementsField
				.getText().replaceAll(",", "")));
		dm.setCondoFees(FieldParser.parseInteger(this.condoFeesField.getText()
				.replaceAll(",", "")));
		dm.setOtherExpenses(FieldParser.parseInteger(this.otherField.getText()
				.replaceAll(",", "")));
		dm.setOptional1Field(FieldParser.parseInteger(this.optional1Field
				.getText().replaceAll(",", "")));
		dm.setOptional2Field(FieldParser.parseInteger(this.optional2Field
				.getText().replaceAll(",", "")));

		dm.setOptional1Label(this.optional1Label.getText());
		dm.setOptional2Label(this.optional2Label.getText());

		if (dm.isOverrideMaintenance()) {
			dm.setMaintenanceB(FieldParser.parseInteger(this.maintenanceFieldB
					.getText()));
		}
		if (dm.isOverrideManagement()) {
			dm.setManagementB(FieldParser.parseInteger(this.managementFieldB
					.getText()));
		}

		dm.updateInterface();		
	}

	@Override
	public void focusGained(FocusEvent e) {
		if (e.getSource() instanceof JTextField) {
			JTextField focusedField = (JTextField) e.getSource();
			focusedField.selectAll();
		}

	}

	@Override
	public void focusLost(FocusEvent e) {
		updateModel();
	}

	@Override
	public void keyPressed(KeyEvent e) {
		if (e.getSource() == propTaxesField) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getInsuranceField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getVacancyRateField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getEnviroReportsField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getApplyMortInsFieldA().requestFocus();
			}
		} else if (e.getSource() == insuranceField) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getWaterSewerField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getPropertyTaxesField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getEnviroReportsField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getApplyMortInsFieldA().requestFocus();
			}
		} else if (e.getSource() == waterSewerField) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getHeatField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getInsuranceField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getEnviroReportsField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getApplyMortInsFieldA().requestFocus();
			}
		} else if (e.getSource() == heatField) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getHydroField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getWaterSewerField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getEnviroReportsField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getApplyMortInsFieldA().requestFocus();
			}
		} else if (e.getSource() == hydroField) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getMaintenanceField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getHeatField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getRepairsImprovementsField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getApplyMortInsFieldA().requestFocus();
			}
		} else if (e.getSource() == maintenanceField) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getManagementField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getHydroField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getRepairsImprovementsField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getCostPerDoorField().requestFocus();
			}
		} else if (e.getSource() == managementField) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getSnowRemovalField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getMaintenanceField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getSellerRebateField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getCostPerDoorField().requestFocus();
			}
		} else if (e.getSource() == snowRemovalField) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getSuperIntendantField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getManagementField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getSellerRebateField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getCostPerDoorField().requestFocus();
			}
		} else if (e.getSource() == superIntendantField) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getAdvertisingField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getSnowRemovalField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getSellerRebateField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getCostPerDoorField().requestFocus();
			}
		} else if (e.getSource() == advertisingField) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getSuppliesField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getSuperIntendantField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getSellerRebateField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getCostPerDoorField().requestFocus();
			}
		} else if (e.getSource() == suppliesField) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getGarbageField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getAdvertisingField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getSellerRebateField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getCostPerDoorField().requestFocus();
			}
		} else if (e.getSource() == garbageField) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getLawnField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getSuppliesField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getSellerRebateField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getCostPerDoorField().requestFocus();
			}
		} else if (e.getSource() == lawnField) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getLicensesField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getGarbageField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getLessCashBackField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getCostPerDoorField().requestFocus();
			}
		} else if (e.getSource() == licensesField) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getAccountingField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getLawnField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getLessCashBackField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getgRMField().requestFocus();
			}
		} else if (e.getSource() == accountingField) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getLegalField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getLicensesField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getLessCashBackField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getCapRateField().requestFocus();
			}
		} else if (e.getSource() == legalField) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getCleaningField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getAccountingField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getLessCashBackField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getCapRateField().requestFocus();
			}
		} else if (e.getSource() == cleaningField) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getPoolField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getLegalField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getLessCashBackField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getRoiPPDGrowthField().requestFocus();
			}
		} else if (e.getSource() == poolField) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getElevatorField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getCleaningField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getLessCashBackField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getRoiPPDGrowthField().requestFocus();
			}
		} else if (e.getSource() == elevatorField) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getPestControlField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getPoolField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getLessCashBackField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getMonthlyProfPerDoorField().requestFocus();
			}
		} else if (e.getSource() == pestControlField) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getReplacementsField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getElevatorField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getLessCashBackField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getDebtCoverageField().requestFocus();
			}
		} else if (e.getSource() == replacementsField) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getCondoFeesField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getPestControlField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getLessCashBackField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getPaybackPeriodField().requestFocus();
			}
		} else if (e.getSource() == condoFeesField) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getOptionalExpensesFieldA().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getReplacementsField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getLessCashBackField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getPaybackPeriodField().requestFocus();
			}
		} else if (e.getSource() == optional1Field) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getOptionalExpensesFieldB().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getCondoFeesField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getLessCashBackField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getPaybackPeriodField().requestFocus();
			}
		} else if (e.getSource() == optional2Field) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getOtherExpensesField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getOptionalExpensesFieldA().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getLessCashBackField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getPaybackPeriodField().requestFocus();
			}
		} else if (e.getSource() == otherField) {
			if (e.getKeyCode() == KeyEvent.VK_DOWN) {
				fm.getRentField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_UP) {
				fm.getOptionalExpensesFieldB().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
				fm.getLessCashBackField().requestFocus();
			} else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
				fm.getPaybackPeriodField().requestFocus();
			}
		}
		if (e.getKeyCode() == KeyEvent.VK_ENTER) {
			updateModel();
		}
	}

	@Override
	public void keyReleased(KeyEvent e) {

	}

	@Override
	public void keyTyped(KeyEvent e) {

	}

	@Override
	public void mouseClicked(MouseEvent e) {
		if (e.getSource() == maintenanceFieldB
				&& maintenanceFieldB.getBackground() != overriddenColor) {
			int response = JOptionPane.showConfirmDialog(this,
					"Would you like to override the Maintenance field?",
					"Override Maintenance?", JOptionPane.YES_NO_OPTION);
			// if response is 'yes'
			if (response == 0) {
				// change field color to overridden color
				maintenanceFieldB.setBackground(overriddenColor);

				// update DataModel flag
				dm.setOverrideMaintenance(true);

				// update JMenuCheckBox
				fm.getMaintenanceOverride().setSelected(true);
			}
		} else if (e.getSource() == managementFieldB
				&& managementFieldB.getBackground() != overriddenColor) {
			int response = JOptionPane.showConfirmDialog(this,
					"Would you like to override the Management field?",
					"Override Management?", JOptionPane.YES_NO_OPTION);
			// if response is 'yes'
			if (response == 0) {
				// change field color to overridden color
				managementFieldB.setBackground(overriddenColor);

				// update DataModel flag
				dm.setOverrideManagement(true);

				// update JMenuCheckBox
				fm.getManagementOverride().setSelected(true);
			}
		}
	}

	@Override
	public void mouseEntered(MouseEvent e) {

	}

	@Override
	public void mouseExited(MouseEvent e) {

	}

	@Override
	public void mousePressed(MouseEvent e) {

	}

	@Override
	public void mouseReleased(MouseEvent e) {
	}
}
